<?php
/**
 * +--------------------------------------------------------+
 * @Created by PhpStorm.
 * @Category ArticleStockController.php
 * @Depiction:
 * Author: hwy
 * Date: 2020/6/19  12:25
 * +--------------------------------------------------------+
 */

namespace App\Http\Controllers\Index;

use App\Http\Controllers\Controller;
use App\Services\StockArticleService;
use Illuminate\Http\Request;

class StockArticleController extends Controller
{
    protected $stockArticleService;

    public function __construct()
    {
        $this->stockArticleService = StockArticleService::getInstance();
    }

    public function index(Request $request)
    {
        $req['perPage'] = 8;
        $hots           = $this->stockArticleService->getList($req);
        $req['perPage'] = 3;
        $req['top']     = 1;
        $tops           = $this->stockArticleService->getList($req);

        $compact = compact('hots', 'tops', 'request');
        return view('index.article_stock.index', $compact);
    }

    public function show(Request $request)
    {
        $list    = $this->stockArticleService->getList($request);
        $compact = compact('list');

        $html              = view('index.article_stock._section', $compact)->render();
        $data['html']      = $html;
        $data['last_page'] = $list['last_page'];
        return response()->json(['code' => 1, 'data' => $data]);
    }

    public function read(Request $request)
    {
        $article = $this->stockArticleService->getRead($request->id);
        $compact = compact('article');
        return view('index.article_stock.read', $compact);

    }

    public function search(Request $request)
    {
        $req['perPage'] = 8;
        $hots           = $this->stockArticleService->getList($req);
        $req['perPage'] = 3;
        $req['top']     = 1;
        $tops           = $this->stockArticleService->getList($req);

        $compact = compact('hots', 'tops', 'request');
        return view('index.article_stock.index', $compact);
    }

}
